// home模块
// 引入api
import {reqGetSearchList} from '@/api'
// 开启命名空间
const namespaced = true
// state：仓库储存数据
const state = {
  searchList: {}
}
// mutations：修改state唯一手段
const mutations = {
  GETSERACHLIST(state, searchList){
    state.searchList = searchList
  }
}
// action：可以书写业务逻辑
const actions = {
  async getSearchList({commit}, params={}){
    let result = await reqGetSearchList(params)
    if (result.code === 200) {
      commit('GETSERACHLIST', result.data)
    }
  }
}
// getters：理解为计算属性，用于简化仓库数据
const getters = {
  attrsList(state){
    // 为什么加 || [] 因为 一开始数据就是空的 所以为了应对那种情况就 加个判断
    return state.searchList.attrsList || []
  },
  goodsList(state){
    return state.searchList.goodsList || []
  },
  trademarkList(state){
    return state.searchList.trademarkList || []
  },
  total(state){
    return state.searchList.total
  }
}

export default {
  namespaced,
  state,
  mutations,
  actions,
  getters
}